//
//  XMLHomeRetweetView.swift
//  Weibo
//
//  Created by mac on 16/5/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit
//转发视图
class XMLHomeRetweetView: UIView {
    
    var homeRetweetViewBottom :Constraint?
    
    var homeCellViewModel :XMLHomeCellViewModel? {
    
        didSet {
        
            retweetContentLable.text = homeCellViewModel?.retweetContent
            
//            picView.picUrls = homeCellViewModel?.home?.retweeted_status?.pic_urls
            homeRetweetViewBottom?.uninstall()
            if let picUrls = homeCellViewModel?.home?.retweeted_status?.pic_urls where picUrls.count > 0 {
            
                picView.hidden = false
                picView.picUrls = picUrls
                
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.homeRetweetViewBottom = make.bottom.equalTo(picView).offset(margin).constraint
                })
                
            }else {
            
                picView.hidden = true
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.homeRetweetViewBottom = make.bottom.equalTo(retweetContentLable).offset(margin).constraint
                })
                
            }
            
            
//            print(homeCellViewModel?.home?.retweeted_status?.pic_urls)
            
        }
    }
    
    private lazy var picView :XMLHomePicView = {
    
        let view = XMLHomePicView()
        view.backgroundColor = self.backgroundColor
        
        return view
    }()
    
    private lazy var retweetContentLable :UILabel = {
    
        let lable = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 14)
        lable.text = "转发"
        lable.numberOfLines = 0
        return lable
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubViews()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   private func addSubViews() {
//    backgroundColor = UIColor.orangeColor()
    
//        self.backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(retweetContentLable)
        addSubview(picView)
    
        retweetContentLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(margin)
            make.leading.equalTo(self).offset(margin)
            make.trailing.equalTo(self).offset(-margin)
    }
    picView.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(retweetContentLable.snp_bottom).offset(margin)
        make.leading.equalTo(retweetContentLable)
//        make.size.equalTo(CGSize(width: 100, height: 100))
        
    }

    
        self.snp_makeConstraints { (make) -> Void in
            self.homeRetweetViewBottom = make.bottom.equalTo(picView).offset(margin).constraint
        }
    
    }

}
